﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Common;

namespace KendoMvcUI.UI.Grid
{

    /// <summary>
    /// A set of options for the subgrid. Below are all the options with their default values 
    ///{ 
    ///plusicon : “ui-icon-plus”,
    ///minusicon : “ui-icon-minus”,
    ///openicon: “ui-icon-carat-1-sw”, 
    ///expandOnLoad: false, 
    ///selectOnExpand : false, 
    ///reloadOnExpand : true 
    ///} 
    ///plusicon and minusicon defies the icons when the grid is collapsed/expanded. A valid name of icon from Theme Roller should be set. 
    ///openicon the icon bellow the minusicon when the subgrid row is expanded 
    ///expandOnLoad when set to true make it so that all rows will be expanded automatically when a new set of data is loaded. 
    ///selectOnLoad when set to true the row is selected when a plusicon is clicked with the mouse. 
    ///reloadOnExpand If set to false the data in the subgrid is loaded only once and all other subsequent clicks just hide or show the data and no more ajax calls are made.
    /// </summary>
    public class SubGridOptionsSettings
    {
        public string Plusicon {get;set;}
        public string Minusicon {get;set;}
        public string Openicon{get;set;} 
        public bool? ExpandOnLoad{get;set;}
        public bool? SelectOnExpand {get;set;}
        public bool? ReloadOnExpand { get; set; }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            if (!string.IsNullOrWhiteSpace(Plusicon))
                sb.Append("plusicon:'"+Plusicon+"',");
            if (Minusicon.IsNullOrWhiteSpace())
                sb.Append("minusicon:'"+Minusicon+"',");
            if (Openicon.IsNullOrWhiteSpace())
                sb.Append("openicon:'"+Openicon+"',");
            if (ExpandOnLoad.HasValue)
                sb.Append("expandOnLoad:"+ExpandOnLoad.Value.ToString().LowercaseFirst()+",");
            if (SelectOnExpand.HasValue)
                sb.Append("selectOnExpand:{0},".Formator(SelectOnExpand.Value.ToString().LowercaseFirst()));
            if (ReloadOnExpand.HasValue)
                sb.Append("reloadOnExpand:{0},".Formator(ReloadOnExpand.Value.ToString().LowercaseFirst()));

            if (sb.Length > 0)
            {
                sb.ToString().TrimEnd(',');
                return "{"+sb.ToString()+"}";
            } 

            return base.ToString();
        }
    }
}
